package hr.ctg.domain.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.validator.NotNull;

@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Table(name = "park")
@NamedQueries( {
		@NamedQuery(name = "Park.findByTip", query = "select p from Park p where p.tip = ? order by p.naziv"),
		@NamedQuery(name = "Park.findByLatLonNotNull", query = "select m from Park m where m.longituda is not null and m.latituda is not null") })
public class Park implements Serializable {
	private int idParka;
	private String naziv;
	private Character tip;
	private String www;
	private Double longituda;
	private Double latituda;
	private Integer zoom;
	private String panoramio;
	private Set<Opis> opisParkas = new HashSet<Opis>(0);
	private Set<DojamPosjetitelja> dojamPosjetiteljas = new HashSet<DojamPosjetitelja>(
			0);
	private Set<DnevnikAktivnosti> dnevnikAktivnostis = new HashSet<DnevnikAktivnosti>(
			0);
	private Set<Slika> slikas = new HashSet<Slika>(0);
	private Set<Objava> objavas = new HashSet<Objava>(0);

	private static final long serialVersionUID = 1L;

	public Park() {
		super();
	}

	@Id
	@Column(name = "id_parka")
	public int getIdParka() {
		return idParka;
	}

	public void setIdParka(final int idParka) {
		this.idParka = idParka;
	}

	public String getNaziv() {
		return naziv;
	}

	public void setNaziv(final String naziv) {
		this.naziv = naziv;
	}

	public Character getTip() {
		return tip;
	}

	public void setTip(final Character tip) {
		this.tip = tip;
	}

	@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "park")
	public Set<Opis> getOpisParkas() {
		return opisParkas;
	}

	public void setOpisParkas(final Set<Opis> opisParkas) {
		this.opisParkas = opisParkas;
	}

	public String getWww() {
		return www;
	}

	public void setWww(final String www) {
		this.www = www;
	}

	@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "park")
	public Set<DojamPosjetitelja> getDojamPosjetiteljas() {
		return dojamPosjetiteljas;
	}

	@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "park")
	public Set<Slika> getSlikas() {
		return slikas;
	}

	public void setSlikas(final Set<Slika> slikas) {
		this.slikas = slikas;
	}

	public void setDojamPosjetiteljas(
			final Set<DojamPosjetitelja> dojamPosjetiteljas) {
		this.dojamPosjetiteljas = dojamPosjetiteljas;
	}

	@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "park")
	public Set<DnevnikAktivnosti> getDnevnikAktivnostis() {
		return dnevnikAktivnostis;
	}

	public void setDnevnikAktivnostis(
			final Set<DnevnikAktivnosti> dnevnikAktivnostis) {
		this.dnevnikAktivnostis = dnevnikAktivnostis;
	}

	@Column(name = "latituda", nullable = false)
	@NotNull
	public Double getLatituda() {
		return latituda;
	}

	@Column(name = "longituda", nullable = false)
	@NotNull
	public Double getLongituda() {
		return longituda;
	}

	public void setLatituda(final Double latituda) {
		this.latituda = latituda;
	}

	public void setLongituda(final Double longituda) {
		this.longituda = longituda;
	}

	@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "park")
	public Set<Objava> getObjavas() {
		return objavas;
	}

	public void setObjavas(final Set<Objava> objavas) {
		this.objavas = objavas;
	}

	public Opis getOpis(final String currentLanguage) {
		if (opisParkas != null) {
			for (final Opis opisObjekta : opisParkas) {
				if (opisObjekta.getJezik().getOznaka().equals(currentLanguage)) {
					return opisObjekta;
				}
			}
		}
		return null;
	}

	@Transient
	public Integer getZoom() {
		return zoom;
	}

	public void setZoom(final Integer zoom) {
		this.zoom = zoom;
	}

	@Column(name = "panoramio")
	public String getPanoramio() {
		return panoramio;
	}

	public void setPanoramio(String panoramio) {
		this.panoramio = panoramio;
	}

}
